#!/bin/bash

# DCtest0 (29 Aug 2006)
# this script (combined with DCtest1 and DCtest2) allows to
# test a compression algorithm, with several possible options,
# on all files of a corpus. The script reports compression ratios
# and compression/decompression times in a Latex-format table.
# Such table is appended to $program.ris

# The script works for any compression algorithm such that:
#   1. if the compressor executable is XXXX, the decompressor is unXXXX
#   2. both compressor and decompressor accept the option -o to name
#      the output file name


# For each experiment this script measures user+system time using the 
# command /usr/bin/time executing each test $num_runs times


if [ $# -lt 4 ] 
then
  echo Usage: $0 program corpus options_file num_runs
  exit 0
fi


program=$1
corpus=$2
options_file=$3
num_runs=$4

echo "*** Begin test (user+system time) ***" >> $program.ris
echo %%% Experiment run on `date` on `hostname` >> $program.ris


# execute DCtest1/DCtest2 for each set of options

options=""
for word in `cat $options_file`;
do
  if [ "$word" = "end" ]      # "end" marks the end of a set of options
  then  
    echo "%% Executing $program $options on corpus $corpus ($num_runs runs)"        >> $program.ris 
    DCtest1 $program $corpus $num_runs $options &> $corpus.ris
    DCtest2 $corpus.ris >> $program.ris
    options=""
  else
    options="$options $word"
  fi
done

echo "*** End test (user+system time) ***" >> $program.ris

# rm -f $corpus.ris

exit 0
